home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / wink24 / src / scrn.c < prev    next >
Text File  |  1993-07-08  |  9KB  |  394 lines

  1. #include    <stdio.h>
  2. #include    <ctype.h>
  3. #include    "defs.h"
  4.  
  5. #define    MAXKAN    240*37
  6.  
  7. #define    DMYKAN    0x1D
  8. #define TABCHR  0x09
  9. #define CRCHR   0x1F
  10. #define memrcpy _rmemcpy
  11.  
  12. extern int    Line_no;
  13. extern short    Line_X,Line_Y;
  14.  
  15. extern void    strcpy();
  16. extern void    memcpy();
  17. extern void    memset();
  18. extern void    Dsp_vram();
  19. extern int    Get_key();
  20. extern void    ins_chr();
  21.  
  22.         UCHAR   vram[MAX_X*MAX_Y*2];
  23.     short    COLOR=7;
  24.     short   dlp_flg=FALSE;
  25.     short    Woff_X=0,Woff_Y=0; 
  26.     short    Wsiz_X=MAX_X,Wsiz_Y=MAX_Y;
  27.     short    Wscr_X=0,Wscr_Y=0;
  28.     short    Wind_flg=FALSE;
  29. static    UCHAR    dram[MAX_X*MAX_Y*2];
  30. static  int     Line_tmp[MAX_Y];
  31.  
  32. BOOL    iskan2(ptr)
  33. LONG    ptr;
  34. {
  35.    int    ch;
  36.  
  37.    ch = *Cnv_ptr(++ptr);
  38.    if ( ptr < btm_ptr && iskanji2(ch) )
  39.     return TRUE;
  40.    else
  41.     return FALSE;
  42. }
  43. UCHAR    *Set_Str(sp,vp,att,str)
  44. UCHAR    *sp,*vp;
  45. int    att;
  46. char    *str;
  47. {
  48.     while ( *str != '\0' ) {
  49.     if ( vp >= (sp+MAX_X*MAX_Y*2) )
  50.         return vp;
  51.         *(vp++) = att;
  52.     *(vp++) = *(str++);
  53.     }
  54.     return vp;
  55. }
  56. void    Set_vram_wind()
  57. {
  58.     int     x,y;
  59.     UCHAR   *dp,*p;
  60.  
  61.     dp = vram + Woff_X * 2 + (MAX_X * 2) * Woff_Y;
  62.     if ( Woff_Y > 0 ) {
  63.     p = dp - (MAX_X * 2);
  64.     if ( Woff_X > 0 ) {
  65.         *(p-2) = COLOR; *(p-1) = 0x98;
  66.     }
  67.     for ( x = 0 ; x < Wsiz_X ; x++ ) {
  68.         *(p++) = COLOR; *(p++) = 0x95;
  69.     }
  70.     if ( (Woff_X + Wsiz_X) < MAX_X ) {
  71.         *(p++) = COLOR; *(p++) = 0x99;
  72.     }
  73.     }
  74.     for ( y = 0 ; y < Wsiz_Y ; y++,dp += (MAX_X * 2) ) {
  75.     if ( Woff_X > 0 ) {
  76.          *(dp-2) = COLOR; *(dp-1) = 0x96;
  77.     }
  78.     if ( (Woff_X + Wsiz_X) < MAX_X ) {
  79.          *(dp+Wsiz_X*2) = COLOR; *(dp+Wsiz_X*2+1) = 0x96;
  80.     }
  81.     }
  82.     if ( (Woff_Y + Wsiz_Y) < MAX_Y ) {
  83.     if ( Woff_X > 0 ) {
  84.         *(dp-2) = COLOR; *(dp-1) = 0x9A;
  85.     }
  86.     for ( x = 0 ; x < Wsiz_X ; x++ ) {
  87.         *(dp++) = COLOR; *(dp++) = 0x95;
  88.     }
  89.     if ( (Woff_X + Wsiz_X) < MAX_X ) {
  90.         *(dp++) = COLOR; *(dp++) = 0x9B;
  91.     }
  92.     }
  93. }
  94. void    Set_vram_line(vp,no)
  95. UCHAR    *vp;
  96. int    no;
  97. {
  98.     int     i;
  99.     char    tmp[12];
  100.  
  101.     if ( Line_tmp[no] >= 0 )
  102.     sprintf(tmp,"%-5d\x96",Line_no+Line_tmp[no]+1);
  103.     else
  104.     strcpy(tmp,"+    \x96");
  105.     for ( i = 0 ; i < 6 ; i++ ) {
  106.     *(vp++) = COLOR; *(vp++) = tmp[i];
  107.     }
  108. }
  109. void    Set_vram_sub()
  110. {
  111.     int     y;
  112.     UCHAR   *sp,*dp;
  113.  
  114.     if ( Wind_flg != ERR ) {
  115.         Set_vram_wind();
  116.         Wind_flg = ERR;
  117.     }
  118.  
  119.     if ( dlp_flg != FALSE ) {
  120.     Wsiz_X -= 6;
  121.     Woff_X += 6;
  122.     }
  123.     if ( (Wscr_X + Wsiz_X) > MAX_X )
  124.     Wscr_X = 0;
  125.     if ( Wscr_X > Cur_X && (Wscr_X = Cur_X - 10) < 0 )
  126.     Wscr_X = 0;
  127.     if ( (Wscr_X + Wsiz_X) <= Cur_X ) {
  128.     Wscr_X = (Cur_X - Wsiz_X) + 10;
  129.     if ( (Wscr_X + Wsiz_X) > MAX_X )
  130.         Wscr_X = MAX_X - Wsiz_X;
  131.     }
  132.     if ( (Wscr_Y + Wsiz_Y) > MAX_Y )
  133.     Wscr_Y = 0;
  134.     if ( Wscr_Y > Cur_Y && (Wscr_Y = Cur_Y - 5) < 0 )
  135.     Wscr_Y = 0;
  136.     if ( (Wscr_Y + Wsiz_Y) <= Cur_Y ) {
  137.     Wscr_Y = (Cur_Y - Wsiz_Y) + 5;
  138.     if ( (Wscr_Y + Wsiz_Y) > MAX_Y )
  139.         Wscr_Y = MAX_Y - Wsiz_Y;
  140.     }
  141.  
  142.     sp = dram + Wscr_X * 2 + (MAX_X * 2) * Wscr_Y;
  143.     dp = vram + Woff_X * 2 + (MAX_X * 2) * Woff_Y;
  144.     if ( dlp_flg == FALSE ) {
  145.         for ( y = 0 ; y < Wsiz_Y ; y++,sp += (MAX_X * 2),dp += (MAX_X * 2) )
  146.         memcpy(dp,sp,Wsiz_X * 2);
  147.     } else {
  148.         for ( y = 0 ; y < Wsiz_Y ; y++,sp += (MAX_X * 2),dp += (MAX_X * 2) ) {
  149.         Set_vram_line(dp-12,y+Wscr_Y);
  150.         memcpy(dp,sp,Wsiz_X * 2);
  151.     }
  152.     }
  153.     Cur_X = Cur_X + Woff_X - Wscr_X;
  154.     Cur_Y = Cur_Y + Woff_Y - Wscr_Y;
  155.  
  156.     if ( dlp_flg != FALSE ) {
  157.     Wsiz_X += 6;
  158.     Woff_X -= 6;
  159.     }
  160. }
  161. void    Set_vram()
  162. {
  163.     int      ch,i,x,y,col,ln,ol;
  164.     register UCHAR   *vp;
  165.     register LONG    ptr;
  166.     UCHAR    *sp;
  167.  
  168.     sp = (Wind_flg != FALSE ? dram : vram);
  169. RESET:
  170.     memset(sp,0,MAX_X * MAX_Y * 2);
  171.     ptr = top_ptr; col = COLOR;
  172.     ol = (-1);
  173.     for ( y = 0 ; y < MAX_Y ; y++ )
  174.     Line_tmp[y] = (-1);
  175.     for ( ln = y = 0 ; y < MAX_Y ; y++ ) {
  176.         vp = sp + (MAX_X * 2) * y;
  177.     if ( ln == ol )
  178.         Line_tmp[y] = (-1);
  179.     else
  180.         ol = Line_tmp[y] = ln;
  181.     for ( x = 0 ; x < MAX_X ; ) {
  182.         if ( chk_ptr != ERR ) {
  183.         if ( ptr >= chk_ptr && ptr < cke_ptr )
  184.             col = ((COLOR - 1)&0x0F) | 0x10;
  185.         else
  186.             col = COLOR;
  187.         }
  188.         if ( ptr == ent_ptr ) {
  189.         Line_X = Cur_X = x;
  190.         Cur_Y = y;
  191.         Line_Y = ln;
  192.         }
  193.         if ( ptr >= btm_ptr ) {
  194.         vp = Set_Str(sp,vp,col,"[EOF]");
  195.         goto ENDOF;
  196.         }
  197.         ch = *Cnv_ptr(ptr);
  198.         if ( ch == '\x0D' ) {
  199.         if ( CONTRL > 0 ) {
  200.             *(vp++) = (col-2)&0x0F;
  201.             *(vp++) = CRCHR;
  202.         }
  203.         ptr += 2;
  204.         ln++;
  205.         break;
  206.         } else if ( ch == '\t' ) {
  207.         i = TAB - (x % TAB);
  208.         if ( CONTRL > 1 && i-- > 0 ) {
  209.             *(vp++) = (col-1)&0x0F;
  210.             *(vp++) = TABCHR;
  211.             x++;
  212.         }
  213.         if ( CONTRL > 1 ) {
  214.             while ( i-- > 0 && x < MAX_X ) {
  215.             *(vp++) = (col-1)&0x0F;
  216.             *(vp++) = '.';
  217.                 x++;
  218.             }
  219.         } else {
  220.             while ( i-- > 0 && x < MAX_X ) {
  221.             *(vp++) = col;
  222.             *(vp++) = ' ';
  223.                 x++;
  224.             }
  225.         }
  226.         ptr++;
  227.         } else if ( iskanji(ch) && iskan2(ptr) != FALSE ) {
  228.         if ( x != (MAX_X - 1) ) {
  229. #ifdef    TOWNS
  230.             *(vp++) = col|0x40;
  231.             *(vp++) = ch; ptr++;
  232.             *(vp++) = col|0x80;
  233.             *(vp++) = *Cnv_ptr(ptr++);
  234. #else
  235.             i = (ch << 8); ptr++;
  236.             i |= (*Cnv_ptr(ptr++) & 0xff);
  237.             i = sjistojis(i);
  238.             *(vp++) = col|0x40;
  239.             *(vp++) = i >> 8;
  240.             *(vp++) = col|0x80;
  241.             *(vp++) = i & 0xff;
  242. #endif
  243.             x += 2;
  244.         } else {
  245.             *(vp++) = col;
  246.             *(vp++) = 0x1C;
  247.             x++;
  248.         }
  249.         } else {
  250.         *(vp++) = col;
  251.         *(vp++) = ch;
  252.         x++; ptr++;
  253.         }
  254.     }
  255.     }
  256.     if ( ptr <= lin_ptr ) {
  257.     for ( i = 0 ; top_ptr < btm_ptr && i < 5 ; i++ ) {
  258.         top_ptr = Nxt_line(top_ptr);
  259.         Line_no++;
  260.     }
  261.     goto RESET;
  262.     }
  263. ENDOF:
  264.     if ( Wind_flg != FALSE )
  265.     Set_vram_sub();
  266. }
  267. void    ASCII_code()
  268. {
  269.     static int no=0;
  270.     int     i,ch,Bk_X,Bk_Y;
  271.     unsigned int ec;
  272.     char    tmp[8];
  273.     UCHAR   *vp;
  274.  
  275.     Bk_X = Cur_X; Bk_Y = Cur_Y;
  276.     memset(dram,0,MAX_X * MAX_Y * 2);
  277.     for ( i = 0 ; i < 256 ; i++ ) {
  278.     sprintf(tmp,"%02X %c ",i,i);
  279.         vp = dram + (i / 16) * 10 + (MAX_X * 2) * (i % 16 + 4);
  280.     *(vp++) = 0x0F; *(vp++) = tmp[0];
  281.     *(vp++) = 0x0F; *(vp++) = tmp[1];
  282.     *(vp++) = 0x0F; *(vp++) = tmp[2];
  283.     *(vp++) = 0x05; *(vp++) = tmp[3];
  284.     *(vp++) = 0x0F; *(vp++) = tmp[4];
  285.     }
  286.  
  287.     for ( ; ; ) {
  288.     Cur_X = (no / 16) * 5 + 3;
  289.     Cur_Y = (no % 16) + 4;
  290.         Dsp_vram(dram);
  291.     ch = Get_key(&ec);
  292.     if ( ch == 0x0D || ec == 0x7300 )
  293.         ins_chr(&no,1);
  294.     else if ( ch == 0x1B || ec == 0x7200 )
  295.         break;
  296.     else if ( ec == 0x4D00 )
  297.         no = (no - 1) & 0xFF;
  298.     else if ( ec == 0x5000 )
  299.         no = (no + 1) & 0xFF;
  300.     else if ( ec == 0x4F00 )
  301.         no = (no - 16) & 0xFF;
  302.     else if ( ec == 0x5100 )
  303.         no = (no + 16) & 0xFF;
  304.     }
  305.     Cur_X = Bk_X; Cur_Y = Bk_Y;
  306. }
  307. int    Kan_code_get(no,arg)
  308. int     no;
  309. char    *arg;
  310. {
  311.     int     cd,hi,lo;
  312.  
  313.     hi = no / 94 + 0x21;
  314.     lo = no % 94 + 0x21;
  315.     cd = ((hi << 8) | lo);
  316.  
  317.     if ( (hi & 1) != 0 )
  318.     lo += 0x1F;
  319.     else
  320.     lo += 0x7D;
  321.     if ( lo >= 0x7F )
  322.     lo++;
  323.     hi = (hi - 0x21 >> 1) + 0x81;
  324.     if ( hi > 0x9F )
  325.     hi += 0x40;
  326.  
  327.     *(arg++) = hi;
  328.     *(arg++) = lo;
  329.     *arg = '\0';
  330.  
  331.     return cd;
  332. }
  333. void    Kan_code_sub(no)
  334. int    no;
  335. {
  336.     int    i,cd;
  337.     char   tmp[12],str[8];
  338.     UCHAR  *vp;
  339.  
  340.     memset(dram,0,MAX_X * MAX_Y * 2);
  341.     for ( i = 0 ; no < MAXKAN && i < 240 ; i++,no++ ) {
  342.     cd = Kan_code_get(no,str);
  343.     sprintf(tmp,"%04X",cd);
  344.         vp = dram + (i / 24) * 16 + (MAX_X * 2) * (i % 24 + 2);
  345.     *(vp++) = 0x0F; *(vp++) = tmp[0];
  346.     *(vp++) = 0x0F; *(vp++) = tmp[1];
  347.     *(vp++) = 0x0F; *(vp++) = tmp[2];
  348.     *(vp++) = 0x0F; *(vp++) = tmp[3];
  349.     *(vp++) = 0x0F; *(vp++) = 0x20;
  350.     *(vp++) = 0x45; *(vp++) = str[0];
  351.     *(vp++) = 0x85; *(vp++) = str[1];
  352.     *(vp++) = 0x0F; *(vp++) = 0x20;
  353.     }
  354. }
  355. void    KANJI_code()
  356. {
  357.     static int cs=0,no=0;
  358.     int     ch,od,Bk_X,Bk_Y;
  359.     unsigned int ec;
  360.     char    str[4];
  361.  
  362.     Bk_X = Cur_X; Bk_Y = Cur_Y;
  363.     for ( od = ERR ; ; ) {
  364.     if ( od != no ) {
  365.         Kan_code_sub(no);
  366.         od = no;
  367.     }
  368.     Cur_X = (cs / 24) * 8 + 5;
  369.     Cur_Y = (cs % 24) + 2;
  370.         Dsp_vram(dram);
  371.     ch = Get_key(&ec);
  372.     if ( ch == 0x0D || ec == 0x7300 ) {
  373.         Kan_code_get(no+cs,str);
  374.         ins_chr(str,2);
  375.     } else if ( ch == 0x1B || ec == 0x7200 )
  376.         break;
  377.     else if ( ec == 0x4D00 && --cs < 0 )
  378.         cs = (240 - 1);
  379.     else if ( ec == 0x5000 && ++cs >= 240 )
  380.         cs = 0;
  381.     else if ( ec == 0x4F00 && (cs -= 24) < 0 )
  382.         cs += 240;
  383.     else if ( ec == 0x5100 && (cs += 24) >= 240 )
  384.         cs -= 240;
  385.     if ( (no + cs) >= MAXKAN )
  386.         cs = (MAXKAN-1) - no;
  387.     else if ( ec == 0x4D04 && no > 0 )
  388.         no -= 240;
  389.     else if ( ec == 0x5004 && (no += 240) >= MAXKAN )
  390.         no -= 240;
  391.     }
  392.     Cur_X = Bk_X; Cur_Y = Bk_Y;
  393. }
  394.